﻿using Microsoft.AspNetCore.Mvc;
using JESAI.Application.Abstractions.Sys;
using JESAI.Framework.Attributes;
using JESAI.Framework.Mvc;

namespace JESAI.Platform.WebApi.Controllers
{
    /// <summary>
    /// 缓存控制器
    /// </summary>
    [ApiController]
    [Route("api/v1/[controller]/[action]")]
    public class CacheController : ApiControllerBase
    {
        public readonly IScheduleService _scheduleService;
        public readonly IWebApiAuthorizationService _webApiAuthorizationService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="configService"></param>
        /// <param name="scheduleService"></param>
        /// <param name="webApiAuthorizationService"></param>
        public CacheController(
            IScheduleService scheduleService,
            IWebApiAuthorizationService webApiAuthorizationService)
        {
            _scheduleService = scheduleService;
            _webApiAuthorizationService= webApiAuthorizationService;
        }

        /// <summary>
        /// 清除缓存
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [WebApiAuthorization]
        public IActionResult ClearCache()
        {
            _scheduleService.LoadAllScheduleToCacheAsync();
            _webApiAuthorizationService.LoadAllAppInfoToCacheAsync();

            return Success("清除缓存成功!");
        }
    }
}
